package org.jivesoftware.smack;

import com.kenai.jbosh.AbstractBody;
import com.kenai.jbosh.BOSHClient;
import com.kenai.jbosh.BOSHClientConnListener;
import com.kenai.jbosh.BOSHClientRequestListener;
import com.kenai.jbosh.BOSHClientResponseListener;
import com.kenai.jbosh.BOSHException;
import com.kenai.jbosh.BOSHMessageEvent;
import com.kenai.jbosh.BodyQName;
import com.kenai.jbosh.ComposableBody;
import com.kenai.jbosh.ComposableBody.Builder;
import java.io.IOException;
import java.io.PipedReader;
import java.io.PipedWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadFactory;
import org.jivesoftware.smack.debugger.SmackDebugger;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Type;
import org.jivesoftware.smack.util.StringUtils;

public class BOSHConnection extends Connection
{
  public static final String BOSH_URI = "http://jabber.org/protocol/httpbind";
  public static final String XMPP_BOSH_NS = "urn:xmpp:xbosh";
  private boolean anonymous;
  protected String authID;
  private boolean authenticated;
  private BOSHClient client;
  private final BOSHConfiguration config;
  private boolean connected = false;
  private boolean done;
  private boolean isFirstInitialization;
  private ExecutorService listenerExecutor;
  private Thread readerConsumer;
  private PipedWriter readerPipe;
  private Roster roster;
  protected String sessionID;
  private String user;
  private boolean wasAuthenticated;

  public BOSHConnection(BOSHConfiguration paramBOSHConfiguration)
  {
    super(paramBOSHConfiguration);
    this.authenticated = false;
    this.anonymous = false;
    this.isFirstInitialization = true;
    this.wasAuthenticated = false;
    this.done = false;
    this.authID = null;
    this.sessionID = null;
    this.user = null;
    this.roster = null;
    this.config = paramBOSHConfiguration;
  }

  public BOSHConnection(boolean paramBoolean, String paramString1, int paramInt, String paramString2, String paramString3)
  {
    super(new BOSHConfiguration(paramBoolean, paramString1, paramInt, paramString2, paramString3));
    this.authenticated = false;
    this.anonymous = false;
    this.isFirstInitialization = true;
    this.wasAuthenticated = false;
    this.done = false;
    this.authID = null;
    this.sessionID = null;
    this.user = null;
    this.roster = null;
    this.config = ((BOSHConfiguration)getConfiguration());
  }

  private void setWasAuthenticated(boolean paramBoolean)
  {
    if (!(this.wasAuthenticated))
      this.wasAuthenticated = paramBoolean;
  }

  // ERROR //
  public void connect()
    throws XMPPException
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 56	org/jivesoftware/smack/BOSHConnection:connected	Z
    //   4: ifeq +13 -> 17
    //   7: new 114	java/lang/IllegalStateException
    //   10: dup
    //   11: ldc 116
    //   13: invokespecial 119	java/lang/IllegalStateException:<init>	(Ljava/lang/String;)V
    //   16: athrow
    //   17: aload_0
    //   18: iconst_0
    //   19: putfield 66	org/jivesoftware/smack/BOSHConnection:done	Z
    //   22: aload_0
    //   23: getfield 121	org/jivesoftware/smack/BOSHConnection:client	Lcom/kenai/jbosh/BOSHClient;
    //   26: ifnull +15 -> 41
    //   29: aload_0
    //   30: getfield 121	org/jivesoftware/smack/BOSHConnection:client	Lcom/kenai/jbosh/BOSHClient;
    //   33: invokevirtual 126	com/kenai/jbosh/BOSHClient:close	()V
    //   36: aload_0
    //   37: aconst_null
    //   38: putfield 121	org/jivesoftware/smack/BOSHConnection:client	Lcom/kenai/jbosh/BOSHClient;
    //   41: aload_0
    //   42: getfield 130	org/jivesoftware/smack/BOSHConnection:saslAuthentication	Lorg/jivesoftware/smack/SASLAuthentication;
    //   45: invokevirtual 135	org/jivesoftware/smack/SASLAuthentication:init	()V
    //   48: aload_0
    //   49: aconst_null
    //   50: putfield 70	org/jivesoftware/smack/BOSHConnection:sessionID	Ljava/lang/String;
    //   53: aload_0
    //   54: aconst_null
    //   55: putfield 68	org/jivesoftware/smack/BOSHConnection:authID	Ljava/lang/String;
    //   58: aload_0
    //   59: getfield 76	org/jivesoftware/smack/BOSHConnection:config	Lorg/jivesoftware/smack/BOSHConfiguration;
    //   62: invokevirtual 139	org/jivesoftware/smack/BOSHConfiguration:getURI	()Ljava/net/URI;
    //   65: aload_0
    //   66: getfield 76	org/jivesoftware/smack/BOSHConnection:config	Lorg/jivesoftware/smack/BOSHConfiguration;
    //   69: invokevirtual 143	org/jivesoftware/smack/BOSHConfiguration:getServiceName	()Ljava/lang/String;
    //   72: invokestatic 149	com/kenai/jbosh/BOSHClientConfig$Builder:create	(Ljava/net/URI;Ljava/lang/String;)Lcom/kenai/jbosh/BOSHClientConfig$Builder;
    //   75: astore_2
    //   76: aload_0
    //   77: getfield 76	org/jivesoftware/smack/BOSHConnection:config	Lorg/jivesoftware/smack/BOSHConfiguration;
    //   80: invokevirtual 153	org/jivesoftware/smack/BOSHConfiguration:isProxyEnabled	()Z
    //   83: ifeq +22 -> 105
    //   86: aload_2
    //   87: aload_0
    //   88: getfield 76	org/jivesoftware/smack/BOSHConnection:config	Lorg/jivesoftware/smack/BOSHConfiguration;
    //   91: invokevirtual 156	org/jivesoftware/smack/BOSHConfiguration:getProxyAddress	()Ljava/lang/String;
    //   94: aload_0
    //   95: getfield 76	org/jivesoftware/smack/BOSHConnection:config	Lorg/jivesoftware/smack/BOSHConfiguration;
    //   98: invokevirtual 160	org/jivesoftware/smack/BOSHConfiguration:getProxyPort	()I
    //   101: invokevirtual 164	com/kenai/jbosh/BOSHClientConfig$Builder:setProxy	(Ljava/lang/String;I)Lcom/kenai/jbosh/BOSHClientConfig$Builder;
    //   104: pop
    //   105: aload_0
    //   106: aload_2
    //   107: invokevirtual 168	com/kenai/jbosh/BOSHClientConfig$Builder:build	()Lcom/kenai/jbosh/BOSHClientConfig;
    //   110: invokestatic 171	com/kenai/jbosh/BOSHClient:create	(Lcom/kenai/jbosh/BOSHClientConfig;)Lcom/kenai/jbosh/BOSHClient;
    //   113: putfield 121	org/jivesoftware/smack/BOSHConnection:client	Lcom/kenai/jbosh/BOSHClient;
    //   116: aload_0
    //   117: new 6	org/jivesoftware/smack/BOSHConnection$1
    //   120: dup
    //   121: aload_0
    //   122: invokespecial 174	org/jivesoftware/smack/BOSHConnection$1:<init>	(Lorg/jivesoftware/smack/BOSHConnection;)V
    //   125: invokestatic 180	java/util/concurrent/Executors:newSingleThreadExecutor	(Ljava/util/concurrent/ThreadFactory;)Ljava/util/concurrent/ExecutorService;
    //   128: putfield 182	org/jivesoftware/smack/BOSHConnection:listenerExecutor	Ljava/util/concurrent/ExecutorService;
    //   131: aload_0
    //   132: getfield 121	org/jivesoftware/smack/BOSHConnection:client	Lcom/kenai/jbosh/BOSHClient;
    //   135: new 16	org/jivesoftware/smack/BOSHConnection$BOSHConnectionListener
    //   138: dup
    //   139: aload_0
    //   140: aload_0
    //   141: invokespecial 185	org/jivesoftware/smack/BOSHConnection$BOSHConnectionListener:<init>	(Lorg/jivesoftware/smack/BOSHConnection;Lorg/jivesoftware/smack/BOSHConnection;)V
    //   144: invokevirtual 189	com/kenai/jbosh/BOSHClient:addBOSHClientConnListener	(Lcom/kenai/jbosh/BOSHClientConnListener;)V
    //   147: aload_0
    //   148: getfield 121	org/jivesoftware/smack/BOSHConnection:client	Lcom/kenai/jbosh/BOSHClient;
    //   151: new 191	org/jivesoftware/smack/BOSHPacketReader
    //   154: dup
    //   155: aload_0
    //   156: invokespecial 192	org/jivesoftware/smack/BOSHPacketReader:<init>	(Lorg/jivesoftware/smack/BOSHConnection;)V
    //   159: invokevirtual 196	com/kenai/jbosh/BOSHClient:addBOSHClientResponseListener	(Lcom/kenai/jbosh/BOSHClientResponseListener;)V
    //   162: aload_0
    //   163: getfield 76	org/jivesoftware/smack/BOSHConnection:config	Lorg/jivesoftware/smack/BOSHConfiguration;
    //   166: invokevirtual 199	org/jivesoftware/smack/BOSHConfiguration:isDebuggerEnabled	()Z
    //   169: ifeq +66 -> 235
    //   172: aload_0
    //   173: invokevirtual 202	org/jivesoftware/smack/BOSHConnection:initDebugger	()V
    //   176: aload_0
    //   177: getfield 62	org/jivesoftware/smack/BOSHConnection:isFirstInitialization	Z
    //   180: ifeq +55 -> 235
    //   183: aload_0
    //   184: getfield 206	org/jivesoftware/smack/BOSHConnection:debugger	Lorg/jivesoftware/smack/debugger/SmackDebugger;
    //   187: invokeinterface 212 1 0
    //   192: ifnull +17 -> 209
    //   195: aload_0
    //   196: aload_0
    //   197: getfield 206	org/jivesoftware/smack/BOSHConnection:debugger	Lorg/jivesoftware/smack/debugger/SmackDebugger;
    //   200: invokeinterface 212 1 0
    //   205: aconst_null
    //   206: invokevirtual 216	org/jivesoftware/smack/BOSHConnection:addPacketListener	(Lorg/jivesoftware/smack/PacketListener;Lorg/jivesoftware/smack/filter/PacketFilter;)V
    //   209: aload_0
    //   210: getfield 206	org/jivesoftware/smack/BOSHConnection:debugger	Lorg/jivesoftware/smack/debugger/SmackDebugger;
    //   213: invokeinterface 219 1 0
    //   218: ifnull +17 -> 235
    //   221: aload_0
    //   222: aload_0
    //   223: getfield 206	org/jivesoftware/smack/BOSHConnection:debugger	Lorg/jivesoftware/smack/debugger/SmackDebugger;
    //   226: invokeinterface 219 1 0
    //   231: aconst_null
    //   232: invokevirtual 222	org/jivesoftware/smack/BOSHConnection:addPacketSendingListener	(Lorg/jivesoftware/smack/PacketListener;Lorg/jivesoftware/smack/filter/PacketFilter;)V
    //   235: aload_0
    //   236: getfield 121	org/jivesoftware/smack/BOSHConnection:client	Lcom/kenai/jbosh/BOSHClient;
    //   239: invokestatic 228	com/kenai/jbosh/ComposableBody:builder	()Lcom/kenai/jbosh/ComposableBody$Builder;
    //   242: ldc 230
    //   244: ldc 27
    //   246: invokevirtual 236	com/kenai/jbosh/ComposableBody$Builder:setNamespaceDefinition	(Ljava/lang/String;Ljava/lang/String;)Lcom/kenai/jbosh/ComposableBody$Builder;
    //   249: ldc 27
    //   251: ldc 238
    //   253: ldc 230
    //   255: invokestatic 244	com/kenai/jbosh/BodyQName:createWithPrefix	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lcom/kenai/jbosh/BodyQName;
    //   258: ldc 246
    //   260: invokevirtual 250	com/kenai/jbosh/ComposableBody$Builder:setAttribute	(Lcom/kenai/jbosh/BodyQName;Ljava/lang/String;)Lcom/kenai/jbosh/ComposableBody$Builder;
    //   263: invokevirtual 253	com/kenai/jbosh/ComposableBody$Builder:build	()Lcom/kenai/jbosh/ComposableBody;
    //   266: invokevirtual 257	com/kenai/jbosh/BOSHClient:send	(Lcom/kenai/jbosh/ComposableBody;)V
    //   269: aload_0
    //   270: monitorenter
    //   271: invokestatic 263	java/lang/System:currentTimeMillis	()J
    //   274: bipush 6
    //   276: invokestatic 268	org/jivesoftware/smack/SmackConfiguration:getPacketReplyTimeout	()I
    //   279: imul
    //   280: i2l
    //   281: ladd
    //   282: lstore 4
    //   284: aload_0
    //   285: getfield 56	org/jivesoftware/smack/BOSHConnection:connected	Z
    //   288: ifne +12 -> 300
    //   291: invokestatic 263	java/lang/System:currentTimeMillis	()J
    //   294: lload 4
    //   296: lcmp
    //   297: iflt +117 -> 414
    //   300: aload_0
    //   301: monitorexit
    //   302: aload_0
    //   303: getfield 56	org/jivesoftware/smack/BOSHConnection:connected	Z
    //   306: ifne +134 -> 440
    //   309: aload_0
    //   310: getfield 66	org/jivesoftware/smack/BOSHConnection:done	Z
    //   313: ifne +127 -> 440
    //   316: aload_0
    //   317: iconst_1
    //   318: putfield 66	org/jivesoftware/smack/BOSHConnection:done	Z
    //   321: new 270	java/lang/StringBuilder
    //   324: dup
    //   325: ldc_w 272
    //   328: invokespecial 273	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   331: aload_0
    //   332: invokevirtual 276	org/jivesoftware/smack/BOSHConnection:getHost	()Ljava/lang/String;
    //   335: invokevirtual 280	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   338: ldc_w 282
    //   341: invokevirtual 280	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   344: aload_0
    //   345: invokevirtual 285	org/jivesoftware/smack/BOSHConnection:getPort	()I
    //   348: invokevirtual 288	java/lang/StringBuilder:append	(I)Ljava/lang/StringBuilder;
    //   351: ldc_w 290
    //   354: invokevirtual 280	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   357: invokevirtual 293	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   360: astore 6
    //   362: new 108	XMPPException
    //   365: dup
    //   366: aload 6
    //   368: new 295	org/jivesoftware/smack/packet/XMPPError
    //   371: dup
    //   372: getstatic 301	org/jivesoftware/smack/packet/XMPPError$Condition:remote_server_timeout	Lorg/jivesoftware/smack/packet/XMPPError$Condition;
    //   375: aload 6
    //   377: invokespecial 304	org/jivesoftware/smack/packet/XMPPError:<init>	(Lorg/jivesoftware/smack/packet/XMPPError$Condition;Ljava/lang/String;)V
    //   380: invokespecial 307	XMPPException:<init>	(Ljava/lang/String;Lorg/jivesoftware/smack/packet/XMPPError;)V
    //   383: athrow
    //   384: astore_1
    //   385: new 108	XMPPException
    //   388: dup
    //   389: new 270	java/lang/StringBuilder
    //   392: dup
    //   393: ldc_w 309
    //   396: invokespecial 273	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   399: aload_0
    //   400: invokevirtual 310	org/jivesoftware/smack/BOSHConnection:getServiceName	()Ljava/lang/String;
    //   403: invokevirtual 280	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   406: invokevirtual 293	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   409: aload_1
    //   410: invokespecial 313	XMPPException:<init>	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   413: athrow
    //   414: aload_0
    //   415: lload 4
    //   417: invokestatic 263	java/lang/System:currentTimeMillis	()J
    //   420: lsub
    //   421: invokestatic 319	java/lang/Math:abs	(J)J
    //   424: invokevirtual 325	java/lang/Object:wait	(J)V
    //   427: goto -143 -> 284
    //   430: astore 7
    //   432: goto -148 -> 284
    //   435: astore_3
    //   436: aload_0
    //   437: monitorexit
    //   438: aload_3
    //   439: athrow
    //   440: return
    //
    // Exception table:
    //   from	to	target	type
    //   22	269	384	java/lang/Exception
    //   414	427	430	java/lang/InterruptedException
    //   271	302	435	finally
    //   414	427	435	finally
    //   436	438	435	finally
  }

  public void disconnect(Presence paramPresence)
  {
    Iterator localIterator;
    if (!(this.connected));
    do
    {
      return;
      shutdown(paramPresence);
      if (this.roster != null)
      {
        this.roster.cleanup();
        this.roster = null;
      }
      this.sendListeners.clear();
      this.recvListeners.clear();
      this.collectors.clear();
      this.interceptors.clear();
      this.wasAuthenticated = false;
      this.isFirstInitialization = true;
      localIterator = getConnectionListeners().iterator();
    }
    while (!(localIterator.hasNext()));
    ConnectionListener localConnectionListener = (ConnectionListener)localIterator.next();
    try
    {
      localConnectionListener.connectionClosed();
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  public String getConnectionID()
  {
    String str;
    if (!(this.connected))
      str = null;
    while (true)
    {
      while (true)
      {
        return str;
        if (this.authID == null)
          break;
        str = this.authID;
      }
      str = this.sessionID;
    }
  }

  // ERROR //
  public Roster getRoster()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 74	org/jivesoftware/smack/BOSHConnection:roster	Lorg/jivesoftware/smack/Roster;
    //   4: ifnonnull +7 -> 11
    //   7: aconst_null
    //   8: astore_1
    //   9: aload_1
    //   10: areturn
    //   11: aload_0
    //   12: getfield 76	org/jivesoftware/smack/BOSHConnection:config	Lorg/jivesoftware/smack/BOSHConfiguration;
    //   15: invokevirtual 388	org/jivesoftware/smack/BOSHConfiguration:isRosterLoadedAtLogin	()Z
    //   18: ifne +10 -> 28
    //   21: aload_0
    //   22: getfield 74	org/jivesoftware/smack/BOSHConnection:roster	Lorg/jivesoftware/smack/Roster;
    //   25: invokevirtual 391	org/jivesoftware/smack/Roster:reload	()V
    //   28: aload_0
    //   29: getfield 74	org/jivesoftware/smack/BOSHConnection:roster	Lorg/jivesoftware/smack/Roster;
    //   32: getfield 394	org/jivesoftware/smack/Roster:rosterInitialized	Z
    //   35: ifne +33 -> 68
    //   38: aload_0
    //   39: getfield 74	org/jivesoftware/smack/BOSHConnection:roster	Lorg/jivesoftware/smack/Roster;
    //   42: astore_3
    //   43: aload_3
    //   44: monitorenter
    //   45: invokestatic 268	org/jivesoftware/smack/SmackConfiguration:getPacketReplyTimeout	()I
    //   48: i2l
    //   49: lstore 5
    //   51: invokestatic 263	java/lang/System:currentTimeMillis	()J
    //   54: lstore 7
    //   56: aload_0
    //   57: getfield 74	org/jivesoftware/smack/BOSHConnection:roster	Lorg/jivesoftware/smack/Roster;
    //   60: getfield 394	org/jivesoftware/smack/Roster:rosterInitialized	Z
    //   63: ifeq +13 -> 76
    //   66: aload_3
    //   67: monitorexit
    //   68: aload_0
    //   69: getfield 74	org/jivesoftware/smack/BOSHConnection:roster	Lorg/jivesoftware/smack/Roster;
    //   72: astore_1
    //   73: goto -64 -> 9
    //   76: lload 5
    //   78: lconst_0
    //   79: lcmp
    //   80: ifle -14 -> 66
    //   83: aload_0
    //   84: getfield 74	org/jivesoftware/smack/BOSHConnection:roster	Lorg/jivesoftware/smack/Roster;
    //   87: lload 5
    //   89: invokevirtual 325	java/lang/Object:wait	(J)V
    //   92: invokestatic 263	java/lang/System:currentTimeMillis	()J
    //   95: lstore 9
    //   97: lload 5
    //   99: lload 9
    //   101: lload 7
    //   103: lsub
    //   104: lsub
    //   105: lstore 5
    //   107: lload 9
    //   109: lstore 7
    //   111: goto -55 -> 56
    //   114: astore 4
    //   116: aload_3
    //   117: monitorexit
    //   118: aload 4
    //   120: athrow
    //   121: astore_2
    //   122: goto -54 -> 68
    //
    // Exception table:
    //   from	to	target	type
    //   45	68	114	finally
    //   83	118	114	finally
    //   38	45	121	java/lang/InterruptedException
    //   118	121	121	java/lang/InterruptedException
  }

  public String getUser()
  {
    return this.user;
  }

  protected void initDebugger()
  {
    this.writer = new Writer(this)
    {
      public void close()
      {
      }

      public void flush()
      {
      }

      public void write(, int paramInt1, int paramInt2)
      {
      }
    };
    try
    {
      this.readerPipe = new PipedWriter();
      this.reader = new PipedReader(this.readerPipe);
      super.initDebugger();
      this.client.addBOSHClientResponseListener(new BOSHClientResponseListener(this)
      {
        public void responseReceived()
        {
          if (paramBOSHMessageEvent.getBody() != null);
          try
          {
            BOSHConnection.access$5(this.this$0).write(paramBOSHMessageEvent.getBody().toXML());
            BOSHConnection.access$5(this.this$0).flush();
            return;
          }
          catch (Exception localException)
          {
          }
        }
      });
      this.client.addBOSHClientRequestListener(new BOSHClientRequestListener(this)
      {
        public void requestSent()
        {
          if (paramBOSHMessageEvent.getBody() != null);
          try
          {
            this.this$0.writer.write(paramBOSHMessageEvent.getBody().toXML());
            return;
          }
          catch (Exception localException)
          {
          }
        }
      });
      this.readerConsumer = new Thread(this)
      {
        private int bufferLength;
        private Thread thread;

        public void run()
        {
          char[] arrayOfChar;
          try
          {
            arrayOfChar = new char[this.bufferLength];
            if (BOSHConnection.access$6(this.this$0) == this.thread)
            {
              if (BOSHConnection.access$7(this.this$0))
                return;
              this.this$0.reader.read(arrayOfChar, 0, this.bufferLength);
            }
          }
          catch (IOException localIOException)
          {
          }
        }
      };
      this.readerConsumer.setDaemon(true);
      this.readerConsumer.start();
      return;
    }
    catch (IOException localIOException)
    {
    }
  }

  public boolean isAnonymous()
  {
    return this.anonymous;
  }

  public boolean isAuthenticated()
  {
    return this.authenticated;
  }

  public boolean isConnected()
  {
    return this.connected;
  }

  public boolean isSecureConnection()
  {
    return false;
  }

  public boolean isUsingCompression()
  {
    return false;
  }

  public void login(String paramString1, String paramString2, String paramString3)
    throws XMPPException
  {
    String str2;
    if (!(isConnected()))
      throw new IllegalStateException("Not connected to server.");
    if (this.authenticated)
      throw new IllegalStateException("Already logged in to server.");
    String str1 = paramString1.toLowerCase().trim();
    if ((this.config.isSASLAuthenticationEnabled()) && (this.saslAuthentication.hasNonAnonymousAuthentication()))
      if (paramString2 != null)
      {
        str2 = this.saslAuthentication.authenticate(str1, paramString2, paramString3);
        if (str2 == null)
          break label266;
        this.user = str2;
        this.config.setServiceName(StringUtils.parseServer(str2));
        if (this.roster == null)
        {
          if (this.rosterStorage != null)
            break label336;
          this.roster = new Roster(this);
        }
      }
    while (true)
    {
      while (true)
      {
        do
        {
          while (true)
          {
            while (true)
            {
              if (this.config.isRosterLoadedAtLogin())
                this.roster.reload();
              if (this.config.isSendPresence())
                sendPacket(new Presence(Presence.Type.available));
              this.authenticated = true;
              this.anonymous = false;
              this.config.setLoginInfo(str1, paramString2, paramString3);
              if ((this.config.isDebuggerEnabled()) && (this.debugger != null))
                this.debugger.userHasLogged(this.user);
              return;
              str2 = this.saslAuthentication.authenticate(str1, paramString3, this.config.getCallbackHandler());
            }
            str2 = new NonSASLAuthentication(this).authenticate(str1, paramString2, paramString3);
          }
          label266: this.user = str1 + "@" + getServiceName();
        }
        while (paramString3 == null);
        this.user = this.user + "/" + paramString3;
      }
      label336: this.roster = new Roster(this, this.rosterStorage);
    }
  }

  public void loginAnonymously()
    throws XMPPException
  {
    String str;
    if (!(isConnected()))
      throw new IllegalStateException("Not connected to server.");
    if (this.authenticated)
      throw new IllegalStateException("Already logged in to server.");
    if ((this.config.isSASLAuthenticationEnabled()) && (this.saslAuthentication.hasAnonymousAuthentication()))
      str = this.saslAuthentication.authenticateAnonymously();
    while (true)
    {
      this.user = str;
      this.config.setServiceName(StringUtils.parseServer(str));
      this.roster = null;
      if (this.config.isSendPresence())
        sendPacket(new Presence(Presence.Type.available));
      this.authenticated = true;
      this.anonymous = true;
      if ((this.config.isDebuggerEnabled()) && (this.debugger != null))
        this.debugger.userHasLogged(this.user);
      return;
      str = new NonSASLAuthentication(this).authenticateAnonymously();
    }
  }

  protected void notifyConnectionError(Exception paramException)
  {
    shutdown(new Presence(Presence.Type.unavailable));
    paramException.printStackTrace();
    Iterator localIterator = getConnectionListeners().iterator();
    if (!(localIterator.hasNext()))
      return;
    ConnectionListener localConnectionListener = (ConnectionListener)localIterator.next();
    try
    {
      localConnectionListener.connectionClosedOnError(paramException);
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  protected void processPacket(Packet paramPacket)
  {
    if (paramPacket == null)
      return;
    Iterator localIterator = getPacketCollectors().iterator();
    while (true)
    {
      while (!(localIterator.hasNext()))
        this.listenerExecutor.submit(new ListenerNotification(this, paramPacket));
      ((PacketCollector)localIterator.next()).processPacket(paramPacket);
    }
  }

  protected void send(ComposableBody paramComposableBody)
    throws BOSHException
  {
    if (!(this.connected))
      throw new IllegalStateException("Not connected to a server!");
    if (paramComposableBody == null)
      throw new NullPointerException("Body mustn't be null!");
    if (this.sessionID != null)
      paramComposableBody = paramComposableBody.rebuild().setAttribute(BodyQName.create("http://jabber.org/protocol/httpbind", "sid"), this.sessionID).build();
    this.client.send(paramComposableBody);
  }

  public void sendPacket(Packet paramPacket)
  {
    if (!(isConnected()))
      throw new IllegalStateException("Not connected to server.");
    if (paramPacket == null)
      throw new NullPointerException("Packet is null.");
    if (!(this.done))
      firePacketInterceptors(paramPacket);
    try
    {
      send(ComposableBody.builder().setPayloadXML(paramPacket.toXML()).build());
      firePacketSendingListeners(paramPacket);
      return;
    }
    catch (BOSHException localBOSHException)
    {
      localBOSHException.printStackTrace();
    }
  }

  public void setRosterStorage(RosterStorage paramRosterStorage)
    throws IllegalStateException
  {
    if (this.roster != null)
      throw new IllegalStateException("Roster is already initialized");
    this.rosterStorage = paramRosterStorage;
  }

  protected void shutdown(Presence paramPresence)
  {
    setWasAuthenticated(this.authenticated);
    this.authID = null;
    this.sessionID = null;
    this.done = true;
    this.authenticated = false;
    this.connected = false;
    this.isFirstInitialization = false;
    try
    {
      this.client.disconnect(ComposableBody.builder().setNamespaceDefinition("xmpp", "urn:xmpp:xbosh").setPayloadXML(paramPresence.toXML()).build());
      Thread.sleep(150L);
      label123: if (this.readerPipe != null);
    }
    catch (Exception localException)
    {
      try
      {
        this.readerPipe.close();
        this.reader = null;
        if (this.reader != null);
      }
      catch (Exception localException)
      {
        try
        {
          this.reader.close();
          this.reader = null;
          if (this.writer != null);
        }
        catch (Exception localException)
        {
          try
          {
            this.writer.close();
            this.writer = null;
            if (this.listenerExecutor != null)
              this.listenerExecutor.shutdown();
            this.readerConsumer = null;
            return;
          }
          catch (Throwable localThrowable1)
          {
            while (true)
            {
              while (true)
              {
                break label123:
                localThrowable2 = localThrowable2;
              }
              localThrowable3 = localThrowable3;
            }
            localException = localException;
          }
        }
      }
    }
  }

  private class BOSHConnectionListener
  implements BOSHClientConnListener
  {
    private final BOSHConnection connection;

    public BOSHConnectionListener(, BOSHConnection paramBOSHConnection2)
    {
      this.connection = paramBOSHConnection2;
    }

    // ERROR //
    public void connectionEvent()
    {
      // Byte code:
      //   0: aload_1
      //   1: invokevirtual 33	com/kenai/jbosh/BOSHClientConnEvent:isConnected	()Z
      //   4: ifeq +249 -> 253
      //   7: aload_0
      //   8: getfield 16	org/jivesoftware/smack/BOSHConnection$BOSHConnectionListener:this$0	Lorg/jivesoftware/smack/BOSHConnection;
      //   11: iconst_1
      //   12: invokestatic 37	org/jivesoftware/smack/BOSHConnection:access$0	(Lorg/jivesoftware/smack/BOSHConnection;Z)V
      //   15: aload_0
      //   16: getfield 16	org/jivesoftware/smack/BOSHConnection$BOSHConnectionListener:this$0	Lorg/jivesoftware/smack/BOSHConnection;
      //   19: invokestatic 41	org/jivesoftware/smack/BOSHConnection:access$1	(Lorg/jivesoftware/smack/BOSHConnection;)Z
      //   22: ifeq +96 -> 118
      //   25: aload_0
      //   26: getfield 16	org/jivesoftware/smack/BOSHConnection$BOSHConnectionListener:this$0	Lorg/jivesoftware/smack/BOSHConnection;
      //   29: iconst_0
      //   30: invokestatic 44	org/jivesoftware/smack/BOSHConnection:access$2	(Lorg/jivesoftware/smack/BOSHConnection;Z)V
      //   33: invokestatic 48	org/jivesoftware/smack/BOSHConnection:getConnectionCreationListeners	()Ljava/util/Collection;
      //   36: invokeinterface 54 1 0
      //   41: astore 13
      //   43: aload 13
      //   45: invokeinterface 59 1 0
      //   50: istore 14
      //   52: iload 14
      //   54: ifne +23 -> 77
      //   57: aload_0
      //   58: getfield 21	org/jivesoftware/smack/BOSHConnection$BOSHConnectionListener:connection	Lorg/jivesoftware/smack/BOSHConnection;
      //   61: astore 6
      //   63: aload 6
      //   65: monitorenter
      //   66: aload_0
      //   67: getfield 21	org/jivesoftware/smack/BOSHConnection$BOSHConnectionListener:connection	Lorg/jivesoftware/smack/BOSHConnection;
      //   70: invokevirtual 62	java/lang/Object:notifyAll	()V
      //   73: aload 6
      //   75: monitorexit
      //   76: return
      //   77: aload 13
      //   79: invokeinterface 66 1 0
      //   84: checkcast 68	org/jivesoftware/smack/ConnectionCreationListener
      //   87: aload_0
      //   88: getfield 21	org/jivesoftware/smack/BOSHConnection$BOSHConnectionListener:connection	Lorg/jivesoftware/smack/BOSHConnection;
      //   91: invokeinterface 72 2 0
      //   96: goto -53 -> 43
      //   99: astore_2
      //   100: aload_0
      //   101: getfield 21	org/jivesoftware/smack/BOSHConnection$BOSHConnectionListener:connection	Lorg/jivesoftware/smack/BOSHConnection;
      //   104: astore_3
      //   105: aload_3
      //   106: monitorenter
      //   107: aload_0
      //   108: getfield 21	org/jivesoftware/smack/BOSHConnection$BOSHConnectionListener:connection	Lorg/jivesoftware/smack/BOSHConnection;
      //   111: invokevirtual 62	java/lang/Object:notifyAll	()V
      //   114: aload_3
      //   115: monitorexit
      //   116: aload_2
      //   117: athrow
      //   118: aload_0
      //   119: getfield 16	org/jivesoftware/smack/BOSHConnection$BOSHConnectionListener:this$0	Lorg/jivesoftware/smack/BOSHConnection;
      //   122: invokestatic 75	org/jivesoftware/smack/BOSHConnection:access$3	(Lorg/jivesoftware/smack/BOSHConnection;)Z
      //   125: ifeq +40 -> 165
      //   128: aload_0
      //   129: getfield 21	org/jivesoftware/smack/BOSHConnection$BOSHConnectionListener:connection	Lorg/jivesoftware/smack/BOSHConnection;
      //   132: aload_0
      //   133: getfield 16	org/jivesoftware/smack/BOSHConnection$BOSHConnectionListener:this$0	Lorg/jivesoftware/smack/BOSHConnection;
      //   136: invokestatic 79	org/jivesoftware/smack/BOSHConnection:access$4	(Lorg/jivesoftware/smack/BOSHConnection;)Lorg/jivesoftware/smack/BOSHConfiguration;
      //   139: invokevirtual 85	org/jivesoftware/smack/BOSHConfiguration:getUsername	()Ljava/lang/String;
      //   142: aload_0
      //   143: getfield 16	org/jivesoftware/smack/BOSHConnection$BOSHConnectionListener:this$0	Lorg/jivesoftware/smack/BOSHConnection;
      //   146: invokestatic 79	org/jivesoftware/smack/BOSHConnection:access$4	(Lorg/jivesoftware/smack/BOSHConnection;)Lorg/jivesoftware/smack/BOSHConfiguration;
      //   149: invokevirtual 88	org/jivesoftware/smack/BOSHConfiguration:getPassword	()Ljava/lang/String;
      //   152: aload_0
      //   153: getfield 16	org/jivesoftware/smack/BOSHConnection$BOSHConnectionListener:this$0	Lorg/jivesoftware/smack/BOSHConnection;
      //   156: invokestatic 79	org/jivesoftware/smack/BOSHConnection:access$4	(Lorg/jivesoftware/smack/BOSHConnection;)Lorg/jivesoftware/smack/BOSHConfiguration;
      //   159: invokevirtual 91	org/jivesoftware/smack/BOSHConfiguration:getResource	()Ljava/lang/String;
      //   162: invokevirtual 95	org/jivesoftware/smack/BOSHConnection:login	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
      //   165: aload_0
      //   166: getfield 16	org/jivesoftware/smack/BOSHConnection$BOSHConnectionListener:this$0	Lorg/jivesoftware/smack/BOSHConnection;
      //   169: invokevirtual 98	org/jivesoftware/smack/BOSHConnection:getConnectionListeners	()Ljava/util/Collection;
      //   172: invokeinterface 54 1 0
      //   177: astore 12
      //   179: aload 12
      //   181: invokeinterface 59 1 0
      //   186: ifeq -129 -> 57
      //   189: aload 12
      //   191: invokeinterface 66 1 0
      //   196: checkcast 100	org/jivesoftware/smack/ConnectionListener
      //   199: invokeinterface 103 1 0
      //   204: goto -25 -> 179
      //   207: astore 10
      //   209: aload_0
      //   210: getfield 16	org/jivesoftware/smack/BOSHConnection$BOSHConnectionListener:this$0	Lorg/jivesoftware/smack/BOSHConnection;
      //   213: invokevirtual 98	org/jivesoftware/smack/BOSHConnection:getConnectionListeners	()Ljava/util/Collection;
      //   216: invokeinterface 54 1 0
      //   221: astore 11
      //   223: aload 11
      //   225: invokeinterface 59 1 0
      //   230: ifeq -173 -> 57
      //   233: aload 11
      //   235: invokeinterface 66 1 0
      //   240: checkcast 100	org/jivesoftware/smack/ConnectionListener
      //   243: aload 10
      //   245: invokeinterface 107 2 0
      //   250: goto -27 -> 223
      //   253: aload_1
      //   254: invokevirtual 110	com/kenai/jbosh/BOSHClientConnEvent:isError	()Z
      //   257: istore 5
      //   259: iload 5
      //   261: ifeq +8 -> 269
      //   264: aload_1
      //   265: invokevirtual 114	com/kenai/jbosh/BOSHClientConnEvent:getCause	()Ljava/lang/Throwable;
      //   268: pop
      //   269: aload_0
      //   270: getfield 16	org/jivesoftware/smack/BOSHConnection$BOSHConnectionListener:this$0	Lorg/jivesoftware/smack/BOSHConnection;
      //   273: iconst_0
      //   274: invokestatic 37	org/jivesoftware/smack/BOSHConnection:access$0	(Lorg/jivesoftware/smack/BOSHConnection;Z)V
      //   277: goto -220 -> 57
      //   280: astore 8
      //   282: aload_0
      //   283: getfield 16	org/jivesoftware/smack/BOSHConnection$BOSHConnectionListener:this$0	Lorg/jivesoftware/smack/BOSHConnection;
      //   286: aload 8
      //   288: invokevirtual 117	org/jivesoftware/smack/BOSHConnection:notifyConnectionError	(Ljava/lang/Exception;)V
      //   291: goto -22 -> 269
      //   294: astore 4
      //   296: aload_3
      //   297: monitorexit
      //   298: aload 4
      //   300: athrow
      //   301: astore 7
      //   303: aload 6
      //   305: monitorexit
      //   306: aload 7
      //   308: athrow
      //
      // Exception table:
      //   from	to	target	type
      //   0	52	99	finally
      //   77	96	99	finally
      //   118	204	99	finally
      //   209	259	99	finally
      //   264	269	99	finally
      //   269	291	99	finally
      //   118	204	207	org/jivesoftware/smack/XMPPException
      //   264	269	280	java/lang/Exception
      //   107	116	294	finally
      //   296	298	294	finally
      //   66	76	301	finally
      //   303	306	301	finally
    }
  }

  private class ListenerNotification
  implements Runnable
  {
    private Packet packet;

    public ListenerNotification(, Packet paramPacket)
    {
      this.packet = paramPacket;
    }

    public void run()
    {
      Iterator localIterator = this.this$0.recvListeners.values().iterator();
      while (true)
      {
        if (!(localIterator.hasNext()))
          return;
        ((Connection.ListenerWrapper)localIterator.next()).notifyListener(this.packet);
      }
    }
  }
}